package com.shop.front.vo.store;

import com.alibaba.fastjson.annotation.JSONField;
import com.shop.jpa.domain.BaseDomain;
import com.shop.util.DecimalUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Transient;
import java.io.Serializable;
import java.math.BigDecimal;

@ApiModel("商品评论统计")
@Data
@Entity
public class StoreProductReplyCountVo extends BaseDomain implements Serializable {

    @ApiModelProperty(value = "id", hidden = true)
	@Id
    @Column(name = "id")
	@JSONField(serialize=false)
    private Long id;

    /**
	 * 总数
	 */
    @ApiModelProperty("总数")
	@Column(name = "total_num")
    private Integer totalNum;

    /**
     * 好评数
     */
    @ApiModelProperty("好评数")
    @Column(name = "good_num")
    private Integer goodNum;

    /**
     * 中评数
     */
    @ApiModelProperty("中评数")
    @Column(name = "mid_num")
    private Integer midNum;

    /**
     * 差评数
     */
    @ApiModelProperty("差评数")
    @Column(name = "poor_num")
    private Integer poorNum;

    @Transient
    @ApiModelProperty("好评率")
    private Double goodRate;
    public Double getGoodRate() {
        if(0 == totalNum) return 100D;
        return DecimalUtil.percent(new BigDecimal(goodNum), new BigDecimal(totalNum)).doubleValue();
    }
}